﻿using System.Configuration;
using System;

namespace Higgs.Web.AtomPub.Configurations
{
    public class FeedCollectionConfigElement : ConfigurationElement
    {
        [ConfigurationProperty("id", IsRequired = true)]
        public string Id
        {
            get { return (string)this["id"]; }
            set { this["id"] = value; }
        }

        [ConfigurationProperty("guid", IsRequired = false)]
        public string Guid
        {
            get { return (string)this["guid"]; }
            set { this["guid"] = value; }
        }

        [ConfigurationProperty("title", IsRequired = false, DefaultValue = "Blog Entry")]
        public string Title
        {
            get { return (string)this["title"]; }
            set { this["title"] = value; }
        }

        [ConfigurationProperty("routePath", IsRequired = false, DefaultValue = "Feed/{id}")]
        public string RoutePath
        {
            get
            {
                var routePath = (string) this["routePath"];
                
                if(routePath.IndexOf("{id}", StringComparison.CurrentCultureIgnoreCase) < 0)
                {
                    if (!routePath.EndsWith("/")) routePath += "/";
                    routePath += "{id}";
                }

                return AtomPubConfigSection.Current.ControllerPath + routePath; 
            }
            set { this["routePath"] = value; }
        }

        public string Path
        {
            get { return RoutePath.RemoveUrlParameter(); }
        }

        public string AbsolutePath
        {
            get { return Path.ToAbsoluteUrl(); }
        }

        [ConfigurationProperty("htmlPath", IsRequired = false)]
        public string HtmlPath
        {
            get { return (string)this["htmlPath"]; }
            set { this["htmlPath"] = value; }
        }

        [ConfigurationProperty("authorName", IsRequired = false, DefaultValue = "Author Name")]
        public string AuthorName
        {
            get { return (string)this["authorName"]; }
            set { this["authorName"] = value; }
        }

        [ConfigurationProperty("authorUrl", IsRequired = false)]
        public string AuthorUrl
        {
            get { return (string)this["authorUrl"]; }
            set { this["authorUrl"] = value; }
        }

        [ConfigurationProperty("rights", IsRequired = false)]
        public string Rights
        {
            get { return (string)this["rights"]; }
            set { this["rights"] = value; }
        }

        [ConfigurationProperty("pageSize", IsRequired = false, DefaultValue = 10)]
        public int PageSize
        {
            get { return (int) this["pageSize"]; }
            set { this["pageSize"] = value; }
        }
    }
}
